home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PRINTER
/
PROHP.ARJ
/
DPUBLISH.PRG
< prev
next >
Wrap
Text File
|
1992-06-23
|
10KB
|
285 lines
/*
┌─────────────────────────────────────────────────────────────────────────┐
│ │
│ Program : publish.prg │
│ │
│ Purpose : demonstrate the use of text manipulation. │
│ │
│ Author : Copyright (C) 1992, I.L.A.,Inc. All Rights reserved. │
│ │
│ Comments: This source code may be distributed and used freely │
│ provided that the copyright notice is not removed. │
│ │
└─────────────────────────────────────────────────────────────────────────┘
This program can teach you a lot on how to get the most of cursor
positioning and text manipulating tricks.
Run the program first and after getting the output follow the program flow
and study it. By changing margins (lm,rm) and nTextColH you can see how
the program fit to the new measures.
This program uses only fixed spacing font. you may modify this program
for use with proportional spacing soft font. you'll have to convert all
row col coordinates to inches and replace mlcount() and LQOUT() function.
*/
#include "prohp.ch"
proc main()
Local lm := 5, rm := 38, nTextColH , nTopM, nVpos, nLp
Local nT,nDayPos,dDate,aMo,nDayBoxLW,aCal,HPCcal:=""
Local nDayT,nDayL,nDayH,nDayW,aMsg
Local aData := {{100,1,"January"},;
{400,2,"February"},;
{372,3,"March"},;
{50,4,"April"},;
{210,5,"May"},;
{400,2,"June"},;
{372,3,"July"},;
{50,4,"August"},;
{210,5,"September"},;
{372,3,"October"},;
{50,4,"November"},;
{350,6,"December"}}
// the next line define a block to calculate the current line width in Inches.
Local bPageW:= {||HP_data(D_RMI)-HP_data(D_LMI)}
// same as above but the result is in columns.
Local bWidth:= {||(HP_data(D_RMI)-HP_data(D_LMI))*HP_data(D_CPI)}
Local bVpos:= {|l|l/HP_data(D_LPI)}
Local cText:="* The legitimate object of goverment is to do for a "+;
"community of people whatever they need to have done, but "+;
"cannot do at all in their separate and individual capacities. "+;
chr(13)+chr(10)+"- Abraham Lincoln (1809-1865)"
// To see the power of ProHP try un comment the next code
/*
cText+=chr(13)+chr(10)+"* Voters quickly forget what a man says."+;
"-Richard M. Nixon"
cText+=chr(13)+chr(10)+"* Whenever any Form of Goverment becomes destructive ..."+;
" it is the Right of the people to alter or abolish it.-"+;
"The Declaration of Independance."
*/
HP_init()
HP_send(.t.)
set2print("dpublish.hpc")
qqout(HP_reset())
qqout(HP_pitch(10,ITALIC)) // courier 10, Italic
nTopM := lqout(cText,eval(bWidth)) // print the text
// Set top margin to the number of lines used by cText +1.
nTopM+=(0.5*HP_data(D_LPI))+1
// set Text Column Height to 30 lines and convert it to Inches.
HP_tmset(nTopM)
HP_rcpos(0,0)
HP_rline(0.01,eval(bPageW)) // draw line
nTextColH := 40 / HP_data(D_LPI) // make text col length to 40 lines
HP_lmset(lm) // set Left Margin
HP_rline(nTextColH,0.01) // print vertical line at left margin
HP_rmset(rm) // set Right margin
HP_rcpos(,rm) // move cursor to right margin at the current row
HP_rline(nTextColH,0.01) // draw vertical line at cursor pos.
HP_rcpos(0,lm) // move to top line, left margin
// fill the area between the margins with gray shade.
HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,2)
nLp := lqout(cText) // print the text
HP_rcpos(1,,.t.) // move one line down
nLp++
// go to Left Margin (inch coordinates). we are not using Row Col. coordinates
// because if the font pitch is changed so does the margin refference.
HP_setpos(,HP_data(D_LMI))
HP_rline(0.01,eval(bPageW)) // draw line across the text col width
// will draw a graph here to the end of column
HP_data(D_SHADOWTYPE,9)
Graphr(nTextColH-((nLp)/HP_data(D_LPI)),eval(bPageW),aData)
// Now we create the next text column
lm:=rm+2 // set new left margin to prev. Right margin + 2 columns.
rm:=75 // set Right margin
HP_clrmrg() // clear margin
HP_rcpos(0,0) // cursor to 0,0
HP_lmset(lm) // set LM
HP_rmset(rm) // set RM
HP_rcpos(0,lm) // Cursor to top row , LM
// draw gray shaded area over the defined text column
HP_BAR(nTextColH,HPcol2i(rm-lm),GFILLGRAY,10)
// print the text
/*
nLp := lqout(cText)
HP_rcpos(1,,.t.) // one line down
nLp++
HP_rcpos(,lm) // and go to left margin
HP_rline(0.01,eval(bPageW)) // draw line
nVpos := eval(bVpos,nLp) // find Vertical position of cursor
*/
nVpos:=0
HP_pitch(12) // courier 12 , If your printer does not support 12 Pitch
// you may get wider text col and the calculation of
// LMI will not be accurate. So check printer before using.
nLp:=lqout(cText)
HP_rcpos(1,,.t.)
nLp++
HP_setpos(,HP_data(D_LMI))
HP_rline(0.01,eval(bPageW))
nVpos += eval(bVpos,nLp) // continue tracking Vertical Cursor pos.
HP_pitch(16)
HP_lpi(8)
nLp:=lqout(cText)
HP_rcpos(1,,.t.)
nLp++ //
HP_setpos(,HP_data(D_LMI)) // Go to left margin
HP_rline(0.01,eval(bPageW)) // draw separator line
nLp++
nVpos += eval(bVpos,nLp) // calc current vertical pos
// now draw this month calendar
aCal:=HPdrawmonth(Date(),nVpos,HP_data(D_LMI),nTextColH-nVpos,eval(bPageW))
aMo:=aCal[1]
HPCcal:=aCal[2]
qqout(HPCcal)
// mark todays date
dDate:=date()
// find where month is starting
nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
// get the desired box pos
nDayPos:=nT+day(dDate)-1
nDayBoxLW:=0.05
// draw a box surrounding the day box
HP_box(aMo[nDayPos,1],aMo[nDayPos,2],aMo[8,1]-aMo[1,1]-nDayBoxLW,;
aMo[2,2]-aMo[1,2]-nDayBoxLW,nDayBoxLW,GFILLBLACK)
// mark todays date
dDate:=date()
// find where month is starting
nT:=dow(ctod(str(month(dDate),2)+'/01/'+str(year(dDate),4)))
// get the desired box pos
nDayPos:=nT+day(dDate)-1
// draw a box surrounding the day box
nDayBoxLW:=0.03 // width of line to draw box
nDayT:=aMo[nDayPos,1] // top coordinate for date box
nDayL:=aMo[nDayPos,2] // left
nDayH:=aMo[8,1]-aMo[1,1]-nDayBoxLW // height of box
nDayW:=aMo[2,2]-aMo[1,2]-nDayBoxLW // Width
HP_box(nDayT,nDayL,nDayH,nDayW,nDayBoxLW,GFILLBLACK) // draw the box
// now we will print inside the box
HP_pitch(16) // small pitch here
HP_lpi(8) // set LPI to 8
aMsg := {"ProHP","Day"} // message array
// and this is very nice
HP_aatsay(nDayT+nDayH-HProw2i(len(aMsg)+1),nDayL+nDayW/2,aMsg,,"C")
HP_clrmrg()
// set a new top margin for this page by adding the current Top Margin Inch
// to the text length.
// ProHP keep track on the the margins settings and store it in HP_data()
// at D_TMI we have the current Top Margin in Inch
HP_tmset((HP_data(D_TMI)+nTextColH) * HP_data(D_LPI))
HP_rcpos(0,0)
HP_rline(0.01,eval(bPageW))
HP_pitch(10)
HP_lpi(6)
HP_BAR( (mlcount(cText,eval(bWidth))+1) / HP_data(D_LPI),;
HPcol2i(eval(bWidth)),GFILLGRAY,20)
lqout(cText)
HP_rcpos(1,,.t.)
HP_setpos(,HP_data(D_LMI))
HP_rline(0.01,eval(bPageW))
HP_reset()
set2screen()
return
Function lqout(cStr,nWidth)
Local nTotLines, crlf := CHR(13)+chr(10), cLine, nLine
nWidth := iif(nWidth == NIL,(HP_data(D_RMI)-HP_data(D_LMI))* ;
HP_data(D_CPI),nWidth)
nTotLines := MLCOUNT(cStr,nWidth)
FOR nLine := 1 TO nTotLines
cLine := MEMOLINE(cStr,nWidth,nLine)
qout(cLine)
NEXT
return nTotLines
FUNCTION graphr(nMaxH,nMaxW,aData)
LOCAL nBarSp := 1, nBarW := 1, nBarH := 1
Local nLw := 0.01 // or HP_data(D_LINEWIDTH)
Local nMaxVal,nBarFactor,i,nPos,nBarLength
Local nOldCpi:=HP_data(D_CPI)
HP_pitch(16,ITALIC)
nBarH := nMaxH/len(aData)
nBarSp := max(nBarH*0.20,2/HP_data(D_LPI))
nBarH:=nBarH-nBarSp-(nBarSp/len(aData))
// find maximum value in array
nPos := AMAX(aData)
IF EMPTY(nPos) // NIL or all zeros
RETURN .F.
ENDIF
// get the highest value in array
nMaxVal := aData[nPos,1]
/*
Create a factor for all array element so their bar length will be
relative to the longest one which will get the length of (Graph Width-
Shadow width).
*/
nBarFactor := (nMaxW-(HP_data(D_SHADOWWIDTH)*2)- ;
(HP_data(D_LINEWIDTH)*2)) / nMaxVal
// draw frame of graph
HP_rbox(nMaxH,nMaxW,0.02)
FOR i:=1 to LEN(aData)
HP_setpos(nBarSp,,.T.) // do a little space
// draw first box
nBarLength :=aData[i,1]*nBarFactor-HP_data(D_SHADOWWIDTH)
HP_rbox(nBarH,nBarLength,nLw,GFILLBLACK)
HP_savecsr() // save csr pos
hp_setpos(nLw,,.t.) // move right to start draw after line width
// draw a bar inside the box
HP_bar(nBarH-nLw,nBarLength-nLw)
HP_restcsr() // restore csr
HP_savecsr() // save csr pos
// print at top of box the message for this box and its value
HP_atsay(-(0.25/HP_data(D_LPI)),1/HP_data(D_CPI),aData[I,3]+;
' ('+ltrim(str(aData[i,1]))+')',.T.)
HP_restcsr() // restore csr pos
HP_setpos(nBarH,,.t.) // move down nBarH
NEXT
HP_pitch(nOldCpi)
RETURN ""
FUNCTION AMax( aArray )
LOCAL nLen, nPos, expLast, nElement
DO CASE
// Invalid argument
CASE VALTYPE( aArray ) <> "A"
RETURN NIL
// Empty argument
CASE EMPTY( aArray )
RETURN 0
OTHERWISE
nLen := LEN( aArray )
nPos := 1
expLast := aArray[1,1]
FOR nElement := 2 TO nLen
IF aArray[nElement,1] > expLast
nPos := nElement
expLast := aArray[nElement,1]
ENDIF
NEXT
ENDCASE
RETURN nPos